<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright 2009 Jan-Kees van Andel.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:t="http://myfaces.apache.org/tomahawk"
        xmlns:o="http://www.jkva.nl/jsf/components">
<f:view>
<head>
    <title>
        <h:outputFormat value="#{sessionBean.mode.label}">
            <f:param value="employee" />
        </h:outputFormat>
    </title>
</head>
<body>
<h:form>
    <h1>
        <h:outputFormat value="#{sessionBean.mode.label}">
            <f:param value="employee" />
        </h:outputFormat>
    </h1>
    <h:messages globalOnly="true" />
    <h:panelGrid columns="3">
        <h:outputLabel value="Name" for="name"/>
        <h:inputText id="name" value="#{employeeDetailsBean.employee.name}" required="true"/>
        <h:message for="name"/>

        <h:outputLabel value="Address" for="address"/>
        <h:inputText id="address" value="#{employeeDetailsBean.employee.address}" required="true"/>
        <h:message for="address"/>

        <h:outputLabel value="Birthdate" for="birthdate"/>
        <h:inputText id="birthdate" value="#{employeeDetailsBean.employee.birthdate}" required="true">
            <f:convertDateTime dateStyle="short" />
        </h:inputText>
        <h:message for="birthdate"/>

        <h:outputLabel value="Company" for="company1" rendered="#{not empty employeeDetailsBean.employee.company}"/>
        <h:outputLabel value="Company" for="company2" rendered="#{    empty employeeDetailsBean.employee.company}"/>
        <h:panelGroup>
            <h:inputText id="company1" value="#{employeeDetailsBean.employee.company.name}" rendered="#{not empty employeeDetailsBean.employee.company}" required="true"/>
            <h:inputText id="company2" value="Choose company"                               rendered="#{    empty employeeDetailsBean.employee.company}" required="true"/>
            <h:inputHidden value="#{employeeDetailsBean.employee.company.id}"               rendered="#{not empty employeeDetailsBean.employee.company}" required="true"/>
            <o:nonValidatingCommandButton action="#{employeeDetailsBean.toCompanyList}" value="X2" />
        </h:panelGroup>
        <h:message for="company1" rendered="#{not empty employeeDetailsBean.employee.company}"/>
        <h:message for="company2" rendered="#{    empty employeeDetailsBean.employee.company}"/>

        <f:facet name="footer">
            <h:panelGroup>
                <h:commandLink action="toEmployeeList" value="Back to list" immediate="true"/>
                <h:commandButton action="#{employeeDetailsBean.save}" value="Save"/>
            </h:panelGroup>
        </f:facet>
    </h:panelGrid>

</h:form>
</body>
</f:view>
</html>